package com.question.view.command.play;

import com.question.Design.SingletonMode;
import com.question.entity.Answer;
import com.question.entity.Question;
import com.question.entity.User;
import com.question.service.IPlayerService;
import com.question.utils.InputOutUtils;
import com.question.utils.MyUtils;

public class AnswerCommand extends PlayerSuper{

	private IPlayerService playerService = SingletonMode.getPlayerService();
	@Override
	protected void exec(User player) {
		InputOutUtils.print("请输入要回答问题的id");
		Integer id = InputOutUtils.inputInteger("id->");
		Question question = playerService.getQuestionById(id);
		if(question != null) {
			InputOutUtils.print("你要回答的问题是->",MyUtils.fillSpace(question.getQuestion_info(), 4),
								"请输入你的答案（放弃回答输入Q)");
			String inVal = InputOutUtils.inputString("", false);
			if("Q".equalsIgnoreCase(inVal)) {InputOutUtils.print("放弃回答");return;}
			Answer answer = new Answer(inVal, player, question);
			playerService.answerQuestion(answer);
			InputOutUtils.print("回答完成，等待提问者采纳");
		}else {
			//输入问题序号不存在
			InputOutUtils.print("你输入的问题ID不存在或已经解决(提示输入LIST查看问题列表)");
		}
	}

}
